#!/bin/bash

# 数据库管理命令脚本

case "$1" in
    "start")
        echo "启动数据库..."
        docker compose up -d
        ;;
    "stop")
        echo "停止数据库..."
        docker compose down
        ;;
    "restart")
        echo "重启数据库..."
        docker compose restart
        ;;
    "logs")
        echo "查看数据库日志..."
        docker compose logs postgres
        ;;
    "connect")
        echo "连接到数据库..."
        docker compose exec postgres psql -U postgres -d product_showcase
        ;;
    "reset")
        echo "重置数据库..."
        docker compose down -v
        docker compose up -d
        ;;
    "status")
        echo "数据库状态..."
        docker compose ps
        ;;
    *)
        echo "用法: $0 {start|stop|restart|logs|connect|reset|status}"
        echo ""
        echo "命令说明:"
        echo "  start   - 启动数据库"
        echo "  stop    - 停止数据库"
        echo "  restart - 重启数据库"
        echo "  logs    - 查看日志"
        echo "  connect - 连接数据库"
        echo "  reset   - 重置数据库（删除所有数据）"
        echo "  status  - 查看状态"
        exit 1
        ;;
esac